﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoApp1
{
    /// <summary>
    /// 打折
    /// </summary>
    public class Discount
    {
        public decimal Calculate(decimal amount, bool isVip)
        {
            var money = ProductDiscount(amount);

            //是否 是Vip
            if (isVip)
            {
                money = money*0.5m;
            }
            return money;
        }

        /// <summary>
        /// 产品打折
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        private decimal ProductDiscount(decimal n)
        {
            if (n < 200)
            {
                //200只能 不打折
                return n;
            }

            // >=200 n  < 500 9折
            if (n < 500)
            {
                return n*0.9m;
            }

            // >=500 n  < 700 8折
            if (n < 700)
            {
                return n * 0.8m;
            }

            // >=700 n  < 900 7折
            if (n < 900)
            {
                return n * 0.7m;
            }

            // >=900 n  < 100 6折
            if (n < 1000)
            {
                return n * 0.6m;
            }
            // 大于等于1000 折
            return n *0.5m;
        }
    }
}
